package cn.com.nes.site.controller.project;

import cn.com.nes.common.web.CommonResult;
import cn.com.nes.site.entity.PageData;
import cn.com.nes.site.entity.bo.project.DispatchedProjectBO;
import cn.com.nes.site.entity.bo.project.ProjectImportCustomersPageBO;
import cn.com.nes.site.entity.bo.project.ProjectQueryBO;
import cn.com.nes.site.entity.vo.project.*;
import cn.com.nes.site.service.project.TProjectService;
import cn.com.nes.site.service.project.dto.ProjectRelationshipDTO;
import cn.com.nes.site.service.project.dto.TProjectDTO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

@Api(tags = {"项目模块-项目管理"})
@Controller
@RequestMapping("/v2/project/manage")
public class ProjectController {

    @Resource
    private TProjectService tProjectService;

    @ApiOperation(value = "项目信息保存", notes = "保存项目信息")
    @RequestMapping(value = "/projectSave", method = RequestMethod.POST)
    public @ResponseBody CommonResult<?> projectSave(@RequestBody ProjectSaveVO vo) throws Exception {
        tProjectService.projectSave(vo.convertToBo());
        return CommonResult.ok("项目信息保存成功");
    }

    @ApiOperation(value = "项目信息列表分页查询", notes = "查询项目分页列表")
    @RequestMapping(value = "/projectPage", method = RequestMethod.GET)
    public @ResponseBody CommonResult<TProjectDTO> projectPage(ProjectPageVO vo) throws Exception {
        return CommonResult.page(tProjectService.projectPage(vo));
    }

    @ApiOperation(value = "项目详情查询", notes = "查询项目详细")
    @RequestMapping(value = "/getProjectDetail", method = RequestMethod.GET)
    public @ResponseBody CommonResult<TProjectDTO> getProjectDetail(@Validated ProjectDetailVO vo) throws Exception {
        return CommonResult.data(tProjectService.getProjectDetail(vo.convertToBo(new ProjectQueryBO())));
    }

    @ApiOperation(value = "项目派单列表分页查询", notes = "查询项目的客户派单信息列表")
    @RequestMapping(value = "/dispatchedProjectPage", method = RequestMethod.GET)
    public @ResponseBody CommonResult<TProjectDTO> dispatchedProjectPage(DispatchedProjectPageVO vo) throws Exception {
        return CommonResult.page(tProjectService.dispatchedProjectPage(vo.convertToBo(new DispatchedProjectBO())));
    }

    /**
     * 查询项目派单分页列表
     * @param vo
     * @return
     */
    @Deprecated
    @RequestMapping(value = "/dispatchedOrderPageForProject", method = RequestMethod.GET)
    public @ResponseBody PageData dispatchedOrderPageForProject(DispatchedProjectPageVO vo) throws Exception {
        return tProjectService.dispatchedOrderPageForProject(vo.convertToBo(new DispatchedProjectBO()));
    }

    @ApiOperation(value = "项目导入客户列表分页查询", notes = "查询项目导入客户信息列表，可按姓名、电话、行政区划查询。")
    @RequestMapping(value = "/getProjectImportCustomers", method = RequestMethod.GET)
    public @ResponseBody CommonResult<ProjectRelationshipDTO> getProjectImportCustomers(
            ProjectImportCustomersPageVO vo) throws Exception {
        return CommonResult.page(tProjectService.getProjectImportCustomers(vo.convertToBo(new ProjectImportCustomersPageBO())));
    }

    @ApiOperation(value = "项目导入客户删除", notes = "删除项目导入客户，可批量删除")
    @RequestMapping(value = "/delProjectImportCustomers", method = RequestMethod.POST)
    public @ResponseBody CommonResult<?> delProjectImportCustomers(
            @RequestBody @Validated DelProjectImportCustomersVO vo) throws Exception {
        Integer count = tProjectService.delProjectImportCustomers(vo);
        return CommonResult.ok("删除成功,共删除" + count + "条客户数据");
    }

    @ApiOperation(value = "项目验收按钮", notes = "项目验收按钮")
    @RequestMapping(value = "/projectAcceptance", method = RequestMethod.POST)
    public @ResponseBody CommonResult<?> projectAcceptance(
            @RequestBody @Validated ProjectAcceptanceVO vo) throws Exception {
        tProjectService.projectAcceptance(vo);
        return CommonResult.ok("项目验收成功");
    }

}
